package com.xsomnus.open.im.authv3.server.handler;

import com.xsomnus.open.im.protocol.request.MessageRequestPacket;
import com.xsomnus.open.im.protocol.response.MessageResponsePacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Date;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/25 0025 15:35
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
public class MessageRequestHandler extends SimpleChannelInboundHandler<MessageRequestPacket> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageRequestPacket requestPacket) {
        MessageResponsePacket responsePacket = new MessageResponsePacket();
        System.out.println(new Date() + ": 收到客户端消息: " + requestPacket.getMessage());
        responsePacket.setMessage("服务端回复【" + requestPacket.getMessage() + "】");
        ctx.channel().writeAndFlush(responsePacket);
    }
}
